
package com.ruoyi.info.task;

import com.ruoyi.info.domain.GoodsInfo;
import com.ruoyi.info.mapper.GoodsInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 库存检查定时任务
 */
@Component
public class StockCheckTask {

    @Autowired
    private GoodsInfoMapper goodsInfoMapper;

    // 存储库存不足的商品（静态变量简单存储）
    public static List<GoodsInfo> lowStockProducts;

    // 每30分钟执行一次
    @Scheduled(cron = "0 0/30 * * * ?")
    public void checkStock() {
        // 查询库存小于等于10的商品（阈值直接写死，简化实现）
        lowStockProducts = goodsInfoMapper.selectLowStock(10);
    }
}

